<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class PublishEnv extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'publish:env';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'generate .env file';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $config      = config('env');
        $envPath     = base_path().'/.env';
        $examplePath = base_path().'/.env.example';
        $content     = file_get_contents($examplePath);
        foreach ($config as $key => $value) {
            $content = str_replace($key, "{$key} = {$value}", $content);
        }
        file_put_contents($envPath, $content);
    }
}
